package org.compression.services.imp;

import java.util.UUID;

import org.compression.mapper.AudioMapper;
import org.compression.mapper.BussineMapper;
import org.compression.services.BussineMangamentService;
import org.compression.util.RedisUtil;
import org.model.auth.Bussine;
import org.model.auth.PageUser;
import org.model.business.AduioAttr;
import org.model.comm.Page;
import org.model.comm.UpdateModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class BussineMangamentServiceImp implements BussineMangamentService{


	@Autowired
	BussineMapper mBookMagamentMapper;

	@Autowired
	RedisUtil	mRedisUtil;
	
	
	
	
	
	@Override
	public Object getMember(Page mPage) {
		PageUser m=new PageUser();
		Object date=(Object) mRedisUtil.get(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		System.out.println(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		if(date!=null) {
			return date;
		}else {
			m.setMember(mBookMagamentMapper.getPageBussiness(mPage));
			m.setTotal(mBookMagamentMapper.getTotal());
		//	mRedisUtil.set(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize(), m);
		}
		return m;
	}

	@Override
	public Object selectName(Bussine mBookMagaments) {
		return mBookMagamentMapper.selectName(mBookMagaments);
	}

	@Override
	public Object add(UpdateModel<Bussine> mModel) {
		Page mPage =mModel.getmPage();
		mRedisUtil.del(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		String uuid=UUID.randomUUID().toString();
	/*	if(mBookMagamentMapper.selectUUID(uuid).size()<=0) {
		}else {
			 uuid=UUID.randomUUID().toString();
		}*/
		mModel.getmBookMagament().setPassword(uuid);;
		return mBookMagamentMapper.insertSelective(mModel.getmBookMagament());
	}

	@Override
	public void deleteByPrimaryKey(UpdateModel<Bussine> mAddModel) {
		Page mPage =mAddModel.getmPage();
		mRedisUtil.del(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		mBookMagamentMapper.deleteByPrimaryKey(mAddModel.getmBookMagament().getId());
	}

	@Override
	public void updateByPrimaryKeySelective(UpdateModel<Bussine> mAddModel) {
		Page mPage =mAddModel.getmPage();
		mRedisUtil.del(this.getClass().getName()+"."+this.getClass().getDeclaredMethods()[0].getName()+"args:"+mPage.getCurrentPageNum()+mPage.getPageSize());
		mBookMagamentMapper.updateByPrimaryKeySelective(mAddModel.getmBookMagament());
	}

}
